<!doctype html>
<html class="x-admin-sm" lang="ch" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>后台登录</title>
    <link rel="stylesheet" th:href="@{/css/login.css}">
    <th:block th:include="template/header::header"></th:block>
</head>
<body class="login-bg">
<div class="login layui-anim layui-anim-up">
    <div class="message">登录</div>
    <div id="darkbannerwrap"></div>

    <form method="post" class="layui-form">
        <input name="username" placeholder="用户名" type="text" lay-verify="required" class="layui-input">
        <hr class="hr15">
        <input name="password" lay-verify="required" placeholder="密码" type="password" class="layui-input">
        <hr class="hr15">
        <input value="登录" lay-submit lay-filter="login" style="width:100%;" type="submit">
        <hr class="hr20">
    </form>
</div>

<script th:inline="javascript">
    layui.use('form', function () {
        var form = layui.form;
        //监听提交
        form.on('submit(login)', function (data) {
            $.ajax({
                url: '/login',
                type: "post",
                data: data.field,
                success: function (res) {
                    // 针对这个结果进行后续
                    if (res.success) {
                        layer.msg(res.msg, {
                            icon: 1,
                            time: 1000
                        }, function () {
                            location.href = '/index'
                        });
                    } else {
                        layer.msg(res.msg);
                    }
                }
            })
            return false;
        });
    });
</script>
</body>
</html>